package com.GUI.lesson1;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class jiangting {
    public static void main(String[] args) {
        Frame frame = new Frame("开始-停止");
        Button button1 = new Button("按下输出文本");

        frame.add(button1,BorderLayout.NORTH);

        frame.pack();
        frame.setVisible(true);
        windowClose(frame);//关闭

        //因为addActionListener需要一个ActionListener，所以我们需要构造一个ActionListener
        MyMonition myMonition = new MyMonition();
        button1.addActionListener(myMonition);

    }

    //关闭窗体的事件
    public static void windowClose(Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

}

//创建一个新类继承  （监听接口ActionListener） 实现监听后要实现的内容
class MyMonition implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("这个是监听返回的内容");
    }
}